﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Text.RegularExpressions;

namespace PhoneNumber_ZipCode
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Dictionary<string, string> patterns = new Dictionary<string, string>();
                patterns.Add("Telephone", @"^\(?\d{3}\)?[\s\-]?\d{4}\-?\d{4}$");
                patterns.Add("IsZIP", @"^\d{5}(\-\d{4})?$");

                while (true)
                {
                    Console.WriteLine("Choose between those options");

                    int i = 0;

                    for (; i < patterns.Count; i++)
                        Console.WriteLine("(" + i + ") - " + patterns.Keys.ElementAt(i) + ". Expression = " + patterns.Values.ElementAt(i));

                    Console.WriteLine("(" + i + ") - Another pattern");
                    string option = Console.ReadLine();

                    string pattern = string.Empty;

                    if (option.Equals(i.ToString()))
                    {
                        Console.WriteLine("Enter your own pattern:");
                        pattern = Console.ReadLine();
                    }
                    else
                        pattern = patterns.Values.ElementAt(Convert.ToInt32(option));

                    Console.WriteLine("Input:");
                    string input = Console.ReadLine();

                    if (input.Equals("quit"))
                        break;
                    else
                    {
                        if (Regex.IsMatch(input, pattern))
                            Console.WriteLine("MATCH!");
                        else
                            Console.WriteLine("NOT MATCH!");

                        Console.ReadKey();
                        Console.Clear();

                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }

        static string ReformatPhone(string s)
        {
            var match = Regex.Match(s, @"^\(?\d{3}\)?[\s\-]?\d{4}\-?\d{4}$");

            return string.Format("({0}) {1}-{2}", match.Groups[0], match.Groups[1], match.Groups[2]);
        }
    }
}
